import { ref, computed } from "vue";
import { defineStore } from "pinia";
import type { CommodityClassify } from "@/openapi-generator";

export const useCommodityClassifyStore = defineStore("commodityClassify", () => {
  const classifys = ref<CommodityClassify[]>([]);
  const setClassifyList = (list: CommodityClassify[]) => {
    classifys.value = list;
  }
  const getClassifyList = async (): Promise<CommodityClassify[]> => {
    let res;
    try {
      res = await $adminApi.commodityClassifyList();
    } catch (error) {
      return []
    }
    setClassifyList(res.data.records);
    return res.data.records;
  }
  const classifyList = computed(() => classifys.value);

  return { classifyList, getClassifyList, setClassifyList };
});
